package com.msmall.community.common.dao.hibernate;

import java.util.Date;
import java.util.List;

import com.msmall.base.dao.hibernate.BaseDaoHibernate;
import com.msmall.base.util.DateUtil;
import com.msmall.community.common.dao.CommendDao;
import com.msmall.community.common.model.Commend;

public class CommendDaoHibernate extends BaseDaoHibernate<Commend, Long> implements CommendDao{

	public CommendDaoHibernate(){
		super(Commend.class);
	}

	public List<Commend> getAllAvailable2D() {
		Date date = DateUtil.dateBefore(new Date(), 1);
		String sql = " from Commend c where c.enabled=1 and c.commendTime >= '" + DateUtil.getYear(date)+ "-" +DateUtil.getMonth(date)+ "-" + DateUtil.getDay(date) + " 00:00:00' order by c.commendLevel asc, c.commendTime desc";
		return super.getHibernateTemplate().find(sql);
	}
	
	public Commend getByTypeAndId(Short type, Long eid){
		String sql = " from Commend c where c.commendType=" + type+ " and c.entityId=" + eid;
		List list = getHibernateTemplate().find(sql);
		if(null != list && list.size() > 0)
			return (Commend) list.get(0);
		return null;
	}
	
}
